<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언
    $findBillCd 			= $_POST['findBillCd'];
    //if (!$expressCd) $expressCd = 'EMS';

	// Table 이름 선언
	$tbname = "tblExpress";

    $curDt =date("Y-m-d");
    if($findBillCd) { $condition = " AND A.billCd LIKE '%{$findBillCd}%' "; }

    $query = "SELECT A.issueDt, A.billCd, A.expressCd, REPLACE(CONVERT(varchar, CAST(A.profit AS money), 1), '.00', '') profit ";
    $query .= ", REPLACE(CONVERT(varchar, CAST(A.compTotalInvAmount AS money), 1), '.00', '') compTotalInvAmount ";
    $query .= ", CASE WHEN F.status='Y' THEN '입.완' ELSE '미입금' END inFlag ";
    $query .= ", REPLACE(CONVERT(varchar, CAST(A.carrTotalInvAmount AS money), 1), '.00', '') carrTotalInvAmount ";
    $query .= ", CASE WHEN G.status='Y' THEN '지급' ELSE '미지급' END outFlag ";
    $query .= ", B.zoneNm, D.nationNm, C.companyKR shipper, A.cargoTon, A.weightTon, E.itemNm cargoType, A.billCd as link ";
    $query .= " FROM {$tbname} A LEFT JOIN tblZoneCd B ON A.destZone=B.zoneCd AND A.expressCd=B.expressCd ";
    $query .= "                  LEFT JOIN tblCompany C ON A.compCd=C.compCd ";
    $query .= "                  LEFT JOIN tblNationCd D ON A.destNationCd=D.nationCd ";
    $query .= "                  LEFT JOIN (SELECT itemCd, itemNm FROM tblComCode WHERE groupCd='0002' AND flag='Y') E ON A.cargoType=E.itemCd ";
    $query .= "                  LEFT JOIN tblIncome F ON A.billCd=F.billCd ";
    $query .= "                  LEFT JOIN tblPayment G ON A.billCd=G.billCd ";
    $query .= " WHERE A.flag='Y' " .$condition ."ORDER BY A.issueDt DESC";
    $query = iconvEncode($query);
$logger->debug($query ."<br>[#FROM:" . $G_remote_ip."#]"); ## 쿼리 로그 작성
    $result = makeJSONArray($query,"GRIDDATA");

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($_SESSION['BID'] ."//" .$output ."<br>[#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>